package student;

import com.tern.db.DataRow;
import com.tern.db.DataTable;
import com.tern.util.Trace;

public class StuCommon {
	
	@SuppressWarnings("unused")
	public static String createSelection(int stuID,int classid,StringBuffer sels) {
		StringBuffer buf = new StringBuffer();
		DataTable dt = new DataTable();
		try {
			StringBuffer sql = new StringBuffer(
					"select cl.classID,cl.classCode,co.courseName,cl.startTime from class cl,coursesInfo co,curricula cu " +
					"where cu.stuID="+stuID+" AND cl.courseID=co.courseID AND cu.classID=cl.classID ");
			sql.append(" order by cl.startTime desc ");
			dt.retriveFromDB(sql.toString());
		} catch (Exception e) {
			Trace.out(Trace.Error, "createSelection:", e);
			return null;
		}
		
		for (int i = 0; i < dt.getRowsCount(); i++) {
			DataRow r = dt.get(i);
			int id = r.getInt(0);

			if (classid < 0) {
				classid = id;
			}

			buf.append("<option value=\"");
			buf.append(id).append("\"");
			if (id == classid) {
				buf.append(" selected");
				sels.append(r.getString(1)+"--"+r.getString(2)+"--"+r.getString(3));
			}

			buf.append(">").append(r.getString(1)+"--"+r.getString(2)+"--"+r.getString(3));
			buf.append("</option>");
		}
		return buf.toString();
	}
}
